/**
 * @author Daniel
 */
var timer;

function createMainMenu()
{
	addDiv('menu', {'width' : 2});
	addTile({'title' : 'Home', 'id' : 'menu', 'action' : 'document.location.hash = "home"; switchboard();'});
	addTile({'title' : 'All Shoes', 'id' : 'menu', 'action' : 'document.location.hash = "all"; switchboard();'});
	addTile({'title' : 'Order Trainers', 'id' : 'menu', 'action' : 'document.location.hash = "order"; switchboard();'});
	addTile({'title' : 'Credits', 'id' : 'menu', 'action' : 'document.location.hash = "credit"; switchboard();'});
	outTiles('menu');
}

function switchboard()
{
	//get anchor
	var uri	= self.document.location.hash.substring(1);
	//call ajax as necassary
	if(uri == "home" || uri == "" || uri == null)
	{
		ajax(
		{
			'url' : 'pages/home.html',
			'success' : function(connection){
				document.getElementById('content').innerHTML = connection.responseText;
			}
		});
	}
	else if(uri == "credit")
	{
		ajax(
		{
			'url' : 'pages/credit.html',
			'success' : function(connection){
				document.getElementById('content').innerHTML = connection.responseText;
			}
		});
	}
	else if(uri == "order")
	{
		ajax(
		{
			'url' : 'orderTrainers.html',
			'success' : function(connection){
				document.getElementById('content').innerHTML = connection.responseText;
			}
		});
	}
	else if(uri == "all")
	{
		ajax(
		{
			'url' : 'pages/all.php',
			'success' : function(connection){
				document.getElementById('content').innerHTML = connection.responseText;
			}
		});
	}
	else
	{
		ajax(
		{
			'url' : 'pages/404.html',
			'success' : function(connection){
				document.getElementById('content').innerHTML = connection.responseText;
			}
		});
	}
}

function offers()
{
	//ajax request for offers
	ajax(
		{
			'url' : 'getOffers.php',
			'success' : function(connection){
				document.getElementById('offer1').innerHTML = connection.responseText;
			}
		});
	ajax(
		{
			'url' : 'getOffers.php?useXML',
			'success' : function(connection){
				document.getElementById('offer2').innerHTML = 
				"Brand: " + connection.responseXML.getElementsByTagName("brandName")[0].childNodes[0].nodeValue +
				", Shoe: " + connection.responseXML.getElementsByTagName("shoeName")[0].childNodes[0].nodeValue +
				", Price: " + connection.responseXML.getElementsByTagName("price")[0].childNodes[0].nodeValue;
			}
		});
	//set timer off
	timer	= setTimeout("offers()", 20000);
}
